/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package events.pose;

import gui.SnazzySpritesGUI;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import snazzysprites.SnazzySprites;
import state.Animation;
import state.Pose;
import state.SnazzySpritesState;
import state.SnazzySpritesStateManager;
import static snazzysprites.SnazzySpritesSettings.*;

/**
 * Handles the creation of a new pose for the current animation
 * @author Andrew Gratta <andrew.gratta@stonybrook.edu>
 */
public class AddPoseHandler implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {
        SnazzySprites singleton = SnazzySprites.getSnazzySprites();
        SnazzySpritesStateManager manager = singleton.getStateManager();
        SnazzySpritesGUI gui = singleton.getGUI();
        Animation anim = manager.getAnimation();
        if (anim != null)
        {
            int selection =JOptionPane.showOptionDialog(gui, 
                    "Would you like to use the current pose as a template?", "Add New Pose", 
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, 
                    null, null, null);
            if (selection == JOptionPane.YES_OPTION)
            {
                manager.addPose(manager.getPose().clone());
            }
            else
            {
                int width = anim.getWidth();
                int height = anim.getHeight();
                manager.addPose(new Pose(width, height));
            }
            gui.setPoseSelectorItems(anim.getPoseCount());
            manager.setState(SnazzySpritesState.SELECT_SHAPE_STATE);
        }
    }
    
}
